#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll ans;
ll T,n,val[N],typ[N],c[N];
void dfs(ll dep){
    if(dep==n+1){
        c[1]=0;
        for(int i=2;i<=n;i++){
            int flag=0;
            for(int j=i-1;j>=1;j--){
                if(typ[j]==typ[i]){
                    flag=1;
                    if(val[i]==val[j]) c[i]=val[i];
                    else c[i]=0;
                    break;
                }
            }
            if(!flag) c[i]=0;
        }
        //for(int i=1;i<=n;i++) cout<<typ[i]<<' ';
        //cout<<'\n';
        //for(int i=1;i<=n;i++) cout<<c[i]<<' ';
        //cout<<'\n';
        ll tmp=0;
        for(int i=1;i<=n;i++) tmp+=c[i];
        ans=max(ans,tmp);
        return;
    }
    typ[dep]=0;
    dfs(dep+1);
    typ[dep]=1;
    dfs(dep+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>val[i];
        memset(typ,0,sizeof(typ));
        memset(c,0,sizeof(c));
        ans=0;
        dfs(1);
        cout<<ans<<'\n';
    }
    return 0;
}
